package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.pojo.TbContent;
import com.dongdongshop.service.ContentService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("content")
@Controller
public class ContentController {
    @DubboReference
    private ContentService contentService;

    @RequestMapping("/toContent")
    public String toShow(){
        return "admin/content";
    }

    @RequestMapping("/listContent")
    @ResponseBody
    public Result listContents(){
        try {
            List<TbContent> list = contentService.listContents();
            return Result.OK().setData(list);
        }catch (Exception e){

            return Result.ER();
        }
    }
    @RequestMapping("/addContent")
    @ResponseBody
    public Result addContent(TbContent tbContent){
        try {
            contentService.addContent(tbContent);
            return Result.OK();
        }catch (Exception e){

            return Result.ER();
        }
    }
    @RequestMapping("/toUpdate")
    @ResponseBody
    public Result toUpdate(Long id){
        try {
            TbContent tbContent = contentService.toUpdate(id);
            return Result.OK().setData(tbContent);
        }catch (Exception e){

            return Result.ER();
        }
    }
    @RequestMapping("/updateContent")
    @ResponseBody
    public Result updateContent(TbContent tbContent){
        try {
            contentService.updateContent(tbContent);
            return Result.OK();
        }catch (Exception e){

            return Result.ER();
        }
    }
    @RequestMapping("/delContent")
    @ResponseBody
    public Result delContent(@RequestParam(value = "ids")List<Long> ids){
        try {
            contentService.delContent(ids);
            return Result.OK();
        }catch (Exception e){

            return Result.ER();
        }
    }
}
